<?php
$username = isset($_POST['username']) ? trim($_POST['username']) : '';
if (empty($username)) {
   echo '<script>alert("用户名必须填写"); window.history.back();</script>';
}
$password = isset($_POST['password']) ? $_POST['password'] : '';

if (mb_strlen($password) < 6 || mb_strlen($password) > 20) {
    echo '密码的长度应该在6-20之间'; exit;
}
// 查询数据库 select * from users where username = $username

$user = [
    'username' => 'zhangsan',
    'password' => '123456'
];
if (empty($user)) {
    echo '用户名不存在'; exit;
}

if ($user['password'] != $password) {
    echo '密码输入错误';exit;
}

echo '登录成功';
?>

<!--<script>-->
<!--    alert('登录失败')-->
<!--    window.history.back()-->
<!--</script>-->
